package fr.umlv.m2.jee.pmlv.persistence.note.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import fr.umlv.m2.jee.pmlv.framework.dao.hibernate.AbstractHibernateDAO;
import fr.umlv.m2.jee.pmlv.persistence.note.UserNote;

@Repository("hibernateUserNoteDAO")
public class HibernateUserNoteDAO 
	extends AbstractHibernateDAO<Long,UserNote > implements IUserNoteDAO {

	@Override
	public List<UserNote> findNoteByUserAndByYear(String uid, int year) {
		return findByQuery("from UserNote as un where un.uid='"+uid+"' and un.year="+year);
	}

	@Override
	public List<UserNote> findNoteBySubjectAndByYear(Long subjectId, int year) {
		return findByQuery("from UserNote as un where un.subject.id="+subjectId+" and un.year="+year);
	}

	@Override
	public UserNote findNoteByUserAndSubjectAndByYear(String uid, Long subjectId, int year) {
		String query = "from UserNote as un where un.uid='"+uid+"' and un.subject.id="+subjectId+" and un.year="+year;
                List<UserNote> tmp = findByQuery(query);
                return ( tmp.isEmpty() ? null : tmp.get(0));
	}
}
